/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SupplierFrame.java
 *
 * Created on 26 Des 12, 21:46:50
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.BankDAO;
import com.ivanbiz.dao.ItemDAO;
import com.ivanbiz.dao.LockDateDAO;
import com.ivanbiz.dao.MemberCustomerDAO;
import com.ivanbiz.dao.PenjualanDAO;
import com.ivanbiz.dao.impl.BankDAOImpl;
import com.ivanbiz.dao.impl.ItemDAOImpl;
import com.ivanbiz.dao.impl.LockDateDAOImpl;
import com.ivanbiz.dao.impl.MemberCustomerDAOImpl;
import com.ivanbiz.dao.impl.PenjualanDAOImpl;
import com.ivanbiz.helper.GlobalConstant;
import com.ivanbiz.helper.MyUniqueNumber;
import com.ivanbiz.helper.RandomList;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.helper.UserSession;
import com.ivanbiz.model.Bank;
import com.ivanbiz.model.Item;
import com.ivanbiz.model.MemberCustomer;
import com.ivanbiz.model.Penjualan;
import com.ivanbiz.model.User;
import com.ivanbiz.report.PenjualanReport;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Administrator
 */
public class InvoiceFrame extends javax.swing.JInternalFrame {

    PenjualanDAO penjualanDAO = new PenjualanDAOImpl();
    ItemDAO itemDAO = new ItemDAOImpl();
    List<Penjualan> listPenjualan = new ArrayList<Penjualan>();
    List listVoid = new ArrayList();
    List listVoidDisplay = new ArrayList();
    List<Item> listItem = new ArrayList<Item>();
    ServiceHelper serviceHelper = new ServiceHelper();
    LockDateDAO lockDateDAO = new LockDateDAOImpl();
    RandomList randomList = new RandomList();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ddmmyyyy");
    SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd MMMM yyyy");
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    User user = UserSession.getUser();
    MemberCustomerDAO memberCustomerDAO = new MemberCustomerDAOImpl();
    List<MemberCustomer> listMemberCustomer = new ArrayList<MemberCustomer>();
    List<Bank> listBank = new ArrayList<Bank>();
    BankDAO bankDAO = new BankDAOImpl();
    double totals = 0;
    int quantity = 0;
    int lock = 0;
    boolean lockSet = false;

    /** Creates new form SupplierFrame */
    public InvoiceFrame() {
        this.setVisible(true);
        initComponents();
        updateData();
        comboSearch.setFocusable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PembayaranDialog = new javax.swing.JDialog();
        jLabel8 = new javax.swing.JLabel();
        comboMemberCustomer = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        buttonBayar = new javax.swing.JButton();
        buttonCancel = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        comboTipePembayaran = new javax.swing.JComboBox();
        comboBank = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        textNo = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        dateJatuhTempo = new org.jdesktop.swingx.JXDatePicker();
        comboPembayaran = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        textDP = new javax.swing.JTextField();
        VoidDialog = new javax.swing.JDialog();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableVoid = new javax.swing.JTable();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableData = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        textTotal = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        textNoTransaksi = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        textTanggalTransaksi = new javax.swing.JTextField();
        comboSearch = new javax.swing.JComboBox();
        textSearch = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jPanel12 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();

        PembayaranDialog.setModal(true);
        PembayaranDialog.setUndecorated(true);

        jLabel8.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel8.setText("Nama Pelanggan");

        comboMemberCustomer.setFont(new java.awt.Font("Monospaced", 1, 14));

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Button", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        buttonBayar.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        buttonBayar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/delete.jpg"))); // NOI18N
        buttonBayar.setText("Bayar");
        buttonBayar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBayarActionPerformed(evt);
            }
        });

        buttonCancel.setFont(new java.awt.Font("Monospaced", 1, 14));
        buttonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/Reset.jpg"))); // NOI18N
        buttonCancel.setText("Cancel");
        buttonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonBayar, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonBayar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel9.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel9.setText("Tipe Pembayaran");

        comboTipePembayaran.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        comboTipePembayaran.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bayar Langsung / Cash", "Debet Card", "Credit Card" }));
        comboTipePembayaran.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboTipePembayaranActionPerformed(evt);
            }
        });

        comboBank.setFont(new java.awt.Font("Monospaced", 1, 14));

        jLabel10.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel10.setText("No / AC");

        jLabel11.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel11.setText("Bank");

        textNo.setFont(new java.awt.Font("Monospaced", 1, 14));

        jLabel15.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel15.setText("Pembayaran");

        jLabel19.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel19.setText("Jatuh Tempo");

        dateJatuhTempo.setFont(new java.awt.Font("Monospaced", 1, 14));

        comboPembayaran.setFont(new java.awt.Font("Monospaced", 1, 14));
        comboPembayaran.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tunai", "Kredit" }));
        comboPembayaran.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboPembayaranActionPerformed(evt);
            }
        });

        jLabel20.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel20.setText("| DP -> Rp.");

        textDP.setFont(new java.awt.Font("Monospaced", 1, 14));

        javax.swing.GroupLayout PembayaranDialogLayout = new javax.swing.GroupLayout(PembayaranDialog.getContentPane());
        PembayaranDialog.getContentPane().setLayout(PembayaranDialogLayout);
        PembayaranDialogLayout.setHorizontalGroup(
            PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PembayaranDialogLayout.createSequentialGroup()
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PembayaranDialogLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PembayaranDialogLayout.createSequentialGroup()
                                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel15))
                                .addGap(14, 14, 14)
                                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(PembayaranDialogLayout.createSequentialGroup()
                                        .addComponent(comboPembayaran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel20)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(textDP, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                                    .addComponent(comboMemberCustomer, 0, 310, Short.MAX_VALUE)))
                            .addGroup(PembayaranDialogLayout.createSequentialGroup()
                                .addComponent(jLabel19)
                                .addGap(36, 36, 36)
                                .addComponent(dateJatuhTempo, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE))
                            .addGroup(PembayaranDialogLayout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboTipePembayaran, 0, 312, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PembayaranDialogLayout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jLabel11)
                        .addGap(28, 28, 28)
                        .addComponent(comboBank, 0, 250, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PembayaranDialogLayout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textNo, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PembayaranDialogLayout.createSequentialGroup()
                        .addContainerGap(172, Short.MAX_VALUE)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        PembayaranDialogLayout.setVerticalGroup(
            PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PembayaranDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(comboMemberCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboPembayaran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20)
                    .addComponent(jLabel15)
                    .addComponent(textDP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dateJatuhTempo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(comboTipePembayaran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBank, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PembayaranDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        VoidDialog.setModal(true);

        tableVoid.setAutoCreateRowSorter(true);
        tableVoid.setFont(new java.awt.Font("Monospaced", 1, 14));
        tableVoid.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableVoid.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableVoidMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tableVoid);

        javax.swing.GroupLayout VoidDialogLayout = new javax.swing.GroupLayout(VoidDialog.getContentPane());
        VoidDialog.getContentPane().setLayout(VoidDialogLayout);
        VoidDialogLayout.setHorizontalGroup(
            VoidDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
        );
        VoidDialogLayout.setVerticalGroup(
            VoidDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tabel Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        tableData.setAutoCreateRowSorter(true);
        tableData.setFont(new java.awt.Font("Monospaced", 1, 14));
        tableData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableData.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableDataMouseClicked(evt);
            }
        });
        tableData.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tableDataKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tableData);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1048, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        textTotal.setEditable(false);
        textTotal.setFont(new java.awt.Font("Monospaced", 1, 70));
        textTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        textTotal.setFocusable(false);

        jLabel2.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel2.setText("No. Transaksi");
        jLabel2.setFocusable(false);

        textNoTransaksi.setEditable(false);
        textNoTransaksi.setFont(new java.awt.Font("Monospaced", 1, 14));
        textNoTransaksi.setFocusable(false);

        jLabel1.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel1.setText("Tgl. Transaksi");
        jLabel1.setFocusable(false);

        textTanggalTransaksi.setEditable(false);
        textTanggalTransaksi.setFont(new java.awt.Font("Monospaced", 1, 14));
        textTanggalTransaksi.setFocusable(false);

        comboSearch.setFont(new java.awt.Font("Monospaced", 1, 14));
        comboSearch.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboSearchItemStateChanged(evt);
            }
        });

        textSearch.setFont(new java.awt.Font("Monospaced", 1, 14));
        textSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textSearchKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textNoTransaksi)
                    .addComponent(textTanggalTransaksi)
                    .addComponent(comboSearch, 0, 195, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textTotal, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textNoTransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(7, 7, 7)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textTanggalTransaksi, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel4.setText("<F1> Focus");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel3.setText("<F2> Input Qty");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel5.setText("<F3> SET");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel7.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel7.setText("<F9> Find");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel12.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel12.setText("<F4> BACK.PJUAL");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel13.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel13.setText("<F10> BAYAR");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addContainerGap())
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel14.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel14.setText("<F11> RE-PRINT");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel14)
                .addContainerGap())
        );

        jPanel12.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel16.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel16.setText("<F12> VOID");

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel16)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textSearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textSearchKeyReleased
//        if (evt.getKeyCode() == KeyEvent.VK_F1) {
//
//            // tableData.setRowSelectionInterval(0,0);
//            //  tableData.setFocusable(true);
//            lock = 1;
//        }
        if (evt.getKeyCode() == KeyEvent.VK_F2) {
            inputQty();
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F3) {
            changetoSet();
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F4) {
            updateTable();
            updateTotal();
            comboSearch.setSelectedIndex(0);
            textSearch.setText("");
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F9) {
            comboSearch.setSelectedIndex(1);
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F10) {
            pembayaran();
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F11) {
            reprint();
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_F12) {
            voids();
            lock = 1;
        } else if (evt.getKeyCode() == KeyEvent.VK_ENTER && comboSearch.getSelectedIndex() == 0) {
            if (lock == 0) {
                addPenjualan();
            }
            if (lock != 0) {
                lock = 0;
            }
        } else if (comboSearch.getSelectedIndex() == 1) {
            if (lock == 0) {
                try {
                    listItem = itemDAO.getDataByLike(Item.class, (String) comboSearch.getSelectedItem(), textSearch.getText());
                    updateTableItem();
                } catch (Exception ex) {
                    Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (lock != 0) {
                lock = 0;
            }
        }
        //  tableData.setFocusable(true);
        // textSearch.setFocusable(true);
    }//GEN-LAST:event_textSearchKeyReleased

    private void tableDataKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableDataKeyReleased
        // textSearch.setFocusable(true);
        if (comboSearch.getSelectedIndex() == 1) {
            if (evt.getKeyCode() == KeyEvent.VK_F1) {
                textSearch.requestFocus();
            }
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                try {
                    System.out.println(tableData.getSelectedRow());
                    Item item = (Item) listItem.get(tableData.getSelectedRow() - 1);
                    Penjualan penjualan = new Penjualan();
                    penjualan.setNoTransaksi(textNoTransaksi.getText());
                    penjualan.setDateTransaksi(lockDateDAO.getDateToday());

                    if (lockSet == true) {
                        penjualan.setQuantity(quantity == 0 ? Integer.parseInt(String.valueOf(item.getLockSet())) : quantity * Integer.parseInt(String.valueOf(item.getLockSet())));
                        penjualan.setSubTotal(item.getHargaJual2());
                        penjualan.setHargaJual(item.getHargaJual2());
                    } else {
                        penjualan.setQuantity(quantity == 0 ? 1 : quantity);
                        penjualan.setSubTotal(item.getHargaJual() * penjualan.getQuantity());
                        penjualan.setHargaJual(item.getHargaJual());
                    }
                    penjualan.setItem(item);
                    penjualan.setDiskon(new Double("0"));
                    penjualan.setMataUang(item.getMataUang());
                    penjualan.setUserPenjualan(user.getUserName());
                    listPenjualan.add(penjualan);
                    listItem.clear();
                    updateTable();
                    updateTotal();
                    comboSearch.setSelectedIndex(0);
                    textSearch.setText(GlobalConstant.EMPTY_STRING);
//                    tableData.setFocusable(true);
                    textSearch.requestFocus();
                } catch (Exception ex) {
                    Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    quantity = 0;
                    lock = 0;
                    lockSet = false;
                    textSearch.setText("");
                }
            }
//            else {
//                int response = JOptionPane.showConfirmDialog(null, GlobalConstant.CANCEL, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
//                if (response == JOptionPane.YES_OPTION) {
//                    listPenjualan.remove(tableData.getSelectedRow());
//                    updateTable();
//                    updateTotal();
//                }
//            }
        } else {
            if (evt.getKeyCode() == KeyEvent.VK_F1) {
                System.out.println("lol2222");
                textSearch.requestFocus();
                //jPanel3.setFocusable(true);

            }
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                System.out.println("aaaa enter");
                int qty = 0;
                double discon = 0;
                Penjualan penjualan = listPenjualan.get(tableData.getSelectedRow());
                qty = Integer.parseInt(tableData.getValueAt(tableData.getSelectedRow(), 3).toString());
                discon = Double.parseDouble(tableData.getValueAt(tableData.getSelectedRow(), 6).toString());
                penjualan.setQuantity(qty);
                if (discon != 0.0 || discon != 0) {
                    penjualan.setDiskon(discon);
                    double h_discon = (penjualan.getItem().getHargaJual() / 100) * penjualan.getDiskon();
                    penjualan.setSubTotal((penjualan.getItem().getHargaJual() - h_discon) * qty);
                } else {
                    penjualan.setDiskon(discon);
                    penjualan.setSubTotal(penjualan.getItem().getHargaJual() * qty);
                }
                listPenjualan.set(tableData.getSelectedRow(), penjualan);
                updateTable();
                updateTotal();
            }
        }
        //textSearch.setFocusable(true);
    }//GEN-LAST:event_tableDataKeyReleased

    private void tableDataMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableDataMouseClicked
        textSearch.setFocusable(true);
        if (evt.getClickCount() == 2) {
            if (comboSearch.getSelectedIndex() == 1) {
                try {
                    Item item = (Item) listItem.get(tableData.getSelectedRow());
                    Penjualan penjualan = new Penjualan();
                    penjualan.setNoTransaksi(textNoTransaksi.getText());
                    penjualan.setDateTransaksi(lockDateDAO.getDateToday());

                    if (lockSet == true) {
                        penjualan.setQuantity(quantity == 0 ? Integer.parseInt(String.valueOf(item.getLockSet())) : quantity * Integer.parseInt(String.valueOf(item.getLockSet())));
                        penjualan.setSubTotal(item.getHargaJual2());
                        penjualan.setHargaJual(item.getHargaJual2());
                    } else {
                        penjualan.setQuantity(quantity == 0 ? 1 : quantity);
                        penjualan.setSubTotal(item.getHargaJual() * penjualan.getQuantity());
                        penjualan.setHargaJual(item.getHargaJual());
                    }
                    penjualan.setItem(item);
                    penjualan.setDiskon(new Double("0"));
                    penjualan.setMataUang(item.getMataUang());
                    penjualan.setUserPenjualan(user.getUserName());
                    listPenjualan.add(penjualan);
                    listItem.clear();
                    updateTable();
                    updateTotal();
                    comboSearch.setSelectedIndex(0);
                    textSearch.setText(GlobalConstant.EMPTY_STRING);
//                    tableData.setFocusable(true);
                    textSearch.setFocusable(true);
                } catch (Exception ex) {
                    Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    quantity = 0;
                    lock = 0;
                    lockSet = false;
                    textSearch.setText("");
                }
            } else {
                System.out.println("eaaa");
                int response = JOptionPane.showConfirmDialog(null, GlobalConstant.CANCEL, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.YES_OPTION) {
                    listPenjualan.remove(tableData.getSelectedRow());
                    updateTable();
                    updateTotal();
                }
            }
        }
        textSearch.setFocusable(true);
    }//GEN-LAST:event_tableDataMouseClicked

    private void buttonBayarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBayarActionPerformed
        if (comboPembayaran.getSelectedIndex() == 0) {
            String response = JOptionPane.showInputDialog(this, "<html><font size=\"5\">Uang  yang dibayar</font></html>", "Bayar", JOptionPane.INFORMATION_MESSAGE);
            PembayaranDialog.setVisible(false);
            if (response != null && !response.equals("0") && !response.equals(GlobalConstant.EMPTY_STRING)) {
                if (totals <= Double.parseDouble(response)) {
                    double kembali = Double.parseDouble(response) - totals;
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">Kembali " + numberFormat.format(kembali) + "</font></html>", "Info", JOptionPane.INFORMATION_MESSAGE);
                    bayar(response, kembali);
                } else {
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">Uang yang dibayar lebih kecil dari Total Harga</font></html>", "Warning", JOptionPane.WARNING_MESSAGE);
                }
            }
        } else {
            String response = JOptionPane.showInputDialog(this, "<html><font size=\"5\">Uang yang dibayar</font></html>", "Bayar", JOptionPane.INFORMATION_MESSAGE);
            PembayaranDialog.setVisible(false);
            if (response != null && !response.equals(GlobalConstant.EMPTY_STRING)) {
                double dp = (textDP.getText().equals(GlobalConstant.EMPTY_STRING) ? new Double(0) : Double.parseDouble(textDP.getText()));
                if (Double.parseDouble(response) < dp) {
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">Uang yang dibayar lebih kecil dari DP</font></html>", "Warning", JOptionPane.WARNING_MESSAGE);
                } else if (dp >= totals) {
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">DP yang dibayar lebih besar / sama dengan Total</font></html>", "Warning", JOptionPane.WARNING_MESSAGE);
                } else {
                    double kembali = Double.parseDouble(response) - dp;
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">Kembali setelah dikurangi DP " + numberFormat.format(kembali) + "</font></html>", "Info", JOptionPane.INFORMATION_MESSAGE);
                    bayar(response, kembali);
                }
            }
        }
}//GEN-LAST:event_buttonBayarActionPerformed

    private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed
        PembayaranDialog.setVisible(false);
}//GEN-LAST:event_buttonCancelActionPerformed

    private void comboTipePembayaranActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTipePembayaranActionPerformed
        if (comboTipePembayaran.getSelectedIndex() != 0) {
            jLabel11.setVisible(true);
            jLabel10.setVisible(true);
            textNo.setVisible(true);
            comboBank.setVisible(true);
        } else {
            jLabel11.setVisible(false);
            jLabel10.setVisible(false);
            textNo.setVisible(false);
            comboBank.setVisible(false);
        }
    }//GEN-LAST:event_comboTipePembayaranActionPerformed

    private void comboSearchItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboSearchItemStateChanged
        if (comboSearch.getSelectedIndex() == 0) {
            updateTable();
            updateTotal();
        }
    }//GEN-LAST:event_comboSearchItemStateChanged

    private void tableVoidMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableVoidMouseClicked
        if (evt.getClickCount() == 2) {
            int select = tableVoid.getSelectedRow();
            List listTemp = (List) listVoid.get(select);
            for (int x = 0; x < listTemp.size(); x++) {
                Penjualan penjualan = (Penjualan) listTemp.get(x);
                penjualan.setNoTransaksi(textNoTransaksi.getText());
                listPenjualan.add(penjualan);
            }
            updateTable();
            updateTableVoids();
            updateTotal();
            listVoid.remove(select);
            listVoidDisplay.remove(select);
            VoidDialog.setVisible(false);
        }
    }//GEN-LAST:event_tableVoidMouseClicked

    private void comboPembayaranActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboPembayaranActionPerformed
        if (comboPembayaran.getSelectedIndex() == 0) {
            jLabel20.setVisible(false);
            textDP.setVisible(false);
            textDP.setText("0");
            jLabel19.setVisible(false);
            dateJatuhTempo.setVisible(false);
        } else {
            jLabel20.setVisible(true);
            textDP.setVisible(true);
            textDP.setText("0");
            jLabel19.setVisible(true);
            dateJatuhTempo.setVisible(true);
        }
    }//GEN-LAST:event_comboPembayaranActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog PembayaranDialog;
    private javax.swing.JDialog VoidDialog;
    private javax.swing.JButton buttonBayar;
    private javax.swing.JButton buttonCancel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox comboBank;
    private javax.swing.JComboBox comboMemberCustomer;
    private javax.swing.JComboBox comboPembayaran;
    private javax.swing.JComboBox comboSearch;
    private javax.swing.JComboBox comboTipePembayaran;
    private org.jdesktop.swingx.JXDatePicker dateJatuhTempo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tableData;
    private javax.swing.JTable tableVoid;
    private javax.swing.JTextField textDP;
    private javax.swing.JTextField textNo;
    private javax.swing.JTextField textNoTransaksi;
    private javax.swing.JTextField textSearch;
    private javax.swing.JTextField textTanggalTransaksi;
    private javax.swing.JTextField textTotal;
    // End of variables declaration//GEN-END:variables

    private void updateData() {
        try {
            clearData();
            totals = 0;
            listPenjualan.clear();
            updateTable();
            updateCombo();
        } catch (Exception ex) {
            Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateTable() {
        Object[] judul = {GlobalConstant.NO, GlobalConstant.KODE_BARCODE, GlobalConstant.NAMA, GlobalConstant.QUANTITY, GlobalConstant.HARGA_JUAL, GlobalConstant.TOTAL};
        Object[][] isi = new Object[listPenjualan.size()][7];
        int x = 0;
        int no = 0;
        double total = 0;
        for (Penjualan penjualan : listPenjualan) {
            isi[x][0] = no += 1;
            isi[x][1] = penjualan.getItem().getKodeBarcode();
            isi[x][2] = penjualan.getItem().getNamaItem();
            isi[x][3] = penjualan.getQuantity();
            isi[x][4] = numberFormat.format(penjualan.getHargaJual());
            isi[x][5] = numberFormat.format(penjualan.getSubTotal());
            isi[x][6] = penjualan.getDiskon();
            x++;
        }

        tableData.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                if (columnIdentifiers.get(columnIndex).equals(GlobalConstant.DISKON) || columnIdentifiers.get(columnIndex).equals(GlobalConstant.QUANTITY)) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        TableColumn column0 = tableData.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
        TableColumn column1 = tableData.getColumnModel().getColumn(1);
        column1.setPreferredWidth(130);
        column1.setMaxWidth(130);
        TableColumn column3 = tableData.getColumnModel().getColumn(3);
        column3.setPreferredWidth(75);
        column3.setMaxWidth(75);
        TableColumn column4 = tableData.getColumnModel().getColumn(4);
        column4.setPreferredWidth(150);
        column4.setMaxWidth(150);
        TableColumn column5 = tableData.getColumnModel().getColumn(5);
        column5.setPreferredWidth(150);
        column5.setMaxWidth(150);
//        TableColumn column6 = tableData.getColumnModel().getColumn(6);
//        column6.setPreferredWidth(150);
//        column6.setMaxWidth(150);
    }

    private void clearData() {
        try {
            textSearch.setFocusable(true);
            textSearch.requestFocusInWindow();
            MyUniqueNumber myUniqueNumber = new MyUniqueNumber();
            myUniqueNumber.setDateUniqueNumber();
            textNoTransaksi.setText(myUniqueNumber.getNoTransaksi());
            // textNoTransaksi.setText("P" + simpleDateFormat.format(lockDateDAO.getDateToday()) + randomList.getGeneratePassword());
            textTanggalTransaksi.setText(simpleDateFormat1.format(lockDateDAO.getDateToday()));
            textSearch.setText(GlobalConstant.EMPTY_STRING);
            textTotal.setText(GlobalConstant.EMPTY_STRING);
            PembayaranDialog.setVisible(false);
        } catch (Exception ex) {
            Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateCombo() {
        Object[] dataClass = serviceHelper.getPropertyClass(Item.class);
        Object[] dataSearch = new Object[2];
        dataSearch[0] = dataClass[1];
        dataSearch[1] = dataClass[2];
        comboSearch.setModel(new DefaultComboBoxModel(dataSearch));
    }

    private void updateTotal() {
        double total = 0;
        for (Penjualan penjualan : listPenjualan) {
            total += penjualan.getSubTotal();
        }
        totals = total;
        textTotal.setText(numberFormat.format(total));
    }

    private void addPenjualan() {
        try {
            Item item = (Item) itemDAO.getDataByEqual(Item.class, (String) comboSearch.getSelectedItem(), textSearch.getText());
            if (null != item) {
                Penjualan penjualan = new Penjualan();
                penjualan.setNoTransaksi(textNoTransaksi.getText());
                //penjualan.setDateTransaksi(lockDateDAO.getDateToday());
                penjualan.setItem(item);
                if (lockSet == true) {
                    penjualan.setQuantity(quantity == 0 ? Integer.parseInt(String.valueOf(item.getLockSet())) : quantity * Integer.parseInt(String.valueOf(item.getLockSet())));
                    penjualan.setSubTotal(item.getHargaJual2());
                    penjualan.setHargaJual(item.getHargaJual2());
                } else {
                    penjualan.setQuantity(quantity == 0 ? 1 : quantity);
                    penjualan.setSubTotal(item.getHargaJual() * penjualan.getQuantity());
                    penjualan.setHargaJual(item.getHargaJual());
                }
                penjualan.setDiskon(new Double("0"));
                penjualan.setMataUang(item.getMataUang());
                penjualan.setUserPenjualan(user.getUserName());
                listPenjualan.add(penjualan);
                updateTable();
                updateTotal();
            } else {
                JOptionPane.showMessageDialog(this, "Kode tidak ditemukan");
            }
        } catch (Exception ex) {
            Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            quantity = 0;
            lock = 0;
            lockSet = false;
            textSearch.setText("");
        }
    }

    private void pembayaran() {
        if (!listPenjualan.isEmpty()) {
            try {
                jLabel11.setVisible(false);
                jLabel10.setVisible(false);
                comboBank.setVisible(false);
                textNo.setVisible(false);
                jLabel19.setVisible(false);
                dateJatuhTempo.setVisible(false);
                comboPembayaran.setSelectedIndex(0);
                jLabel20.setVisible(false);
                textDP.setText("0");
                listMemberCustomer = memberCustomerDAO.getAll(MemberCustomer.class);
                updateMemberCustomer();
                listBank = bankDAO.getAll(Bank.class);
                updateBank();
                comboTipePembayaran.setSelectedIndex(0);
                PembayaranDialog.setSize(450, 275);
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                Dimension frameSize = PembayaranDialog.getSize();
                PembayaranDialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
                PembayaranDialog.setVisible(true);
            } catch (Exception ex) {
                Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void inputQty() {
        String response = JOptionPane.showInputDialog(this, GlobalConstant.MSK_JML_QTY, "Jumlah Quantity");
        if (response != null && !response.equals("0") && !response.equals(GlobalConstant.EMPTY_STRING)) {
            quantity = Integer.parseInt(response);
        } else if (response.equals(GlobalConstant.NOL)) {
            JOptionPane.showMessageDialog(this, GlobalConstant.JML_QTY + GlobalConstant.SPACE + GlobalConstant.NOL);
        }
    }

    private void updateTableItem() {
        Object[] judul = {GlobalConstant.NO, GlobalConstant.KODE_BARCODE, GlobalConstant.NAMA, GlobalConstant.STOCK, GlobalConstant.HARGA_JUAL, GlobalConstant.HARGA_JUAL_SET};
        Object[][] isi = new Object[listItem.size()][6];
        int x = 0;
        int no = 0;
        double total = 0;
        for (Item item : listItem) {
            isi[x][0] = no += 1;
            isi[x][1] = item.getKodeBarcode();
            isi[x][2] = item.getNamaItem();
            isi[x][3] = item.getStock();
            isi[x][4] = numberFormat.format(item.getHargaJual());
            isi[x][5] = numberFormat.format(item.getHargaJual2());
            x++;
        }

        tableData.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                if (columnIdentifiers.get(columnIndex).equals(GlobalConstant.DISKON) || columnIdentifiers.get(columnIndex).equals(GlobalConstant.QUANTITY)) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        TableColumn column0 = tableData.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
        TableColumn column1 = tableData.getColumnModel().getColumn(1);
        column1.setPreferredWidth(150);
        column1.setMaxWidth(150);
        TableColumn column3 = tableData.getColumnModel().getColumn(3);
        column3.setPreferredWidth(75);
        column3.setMaxWidth(75);
        TableColumn column4 = tableData.getColumnModel().getColumn(4);
        column4.setPreferredWidth(150);
        column4.setMaxWidth(150);
        TableColumn column5 = tableData.getColumnModel().getColumn(5);
        column5.setPreferredWidth(150);
        column5.setMaxWidth(150);
    }

    private void updateMemberCustomer() {
        Object data[] = new Object[listMemberCustomer.size()];
        int x = 0;
        for (MemberCustomer memberCustomer : listMemberCustomer) {
            data[x] = memberCustomer.getNama() + " ( " + memberCustomer.getKodeMember() + " )";
            x++;
        }
        comboMemberCustomer.setModel(new DefaultComboBoxModel(data));
    }

    private void updateBank() {
        Object data[] = new Object[listBank.size()];
        int x = 0;
        for (Bank bank : listBank) {
            data[x] = bank.getNama();
            x++;
        }
        comboBank.setModel(new DefaultComboBoxModel(data));
    }

    private void changetoSet() {
        int response = JOptionPane.showConfirmDialog(null, GlobalConstant.SET, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            lockSet = true;
        }
    }

    private void reprint() {
        String response = JOptionPane.showInputDialog(this, "<html><font size=\"5\">Input No Transaksi</font></html>", "Re-Print", JOptionPane.INFORMATION_MESSAGE);
        if (!response.equals(GlobalConstant.EMPTY_STRING)) {
            try {
                listPenjualan = penjualanDAO.getDataByEquals(Penjualan.class, "noTransaksi", response);
                if (!listPenjualan.isEmpty()) {
                    PenjualanReport penjualanReport = new PenjualanReport();
                    penjualanReport.invoicePenjualan(listPenjualan);
                    penjualanReport.suratJalanPenjualan(listPenjualan);
                } else {
                    JOptionPane.showMessageDialog(null, "<html><font size=\"5\" face=\"Tahoma\">No Transaksi tidak ditemukan</font></html>", "Info", JOptionPane.INFORMATION_MESSAGE);
                }
            } catch (Exception ex) {
                Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void voids() {
        if (!listPenjualan.isEmpty()) {
            listVoidDisplay.add("VOIDS " + listVoid.size());
            List listTemp = new ArrayList();
            for (Penjualan penjualan : listPenjualan) {
                listTemp.add(penjualan);
            }
            updateTableVoids();
            listVoid.add(listTemp);
            listPenjualan.clear();
            updateTable();
            VoidDialog.setSize(400, 200);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = VoidDialog.getSize();
            VoidDialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
            VoidDialog.setVisible(true);
        } else {
            updateTableVoids();
            VoidDialog.setSize(400, 200);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = VoidDialog.getSize();
            VoidDialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
            VoidDialog.setVisible(true);
        }
        updateTotal();
    }

    private void updateTableVoids() {
        Object[] judul = {GlobalConstant.NO, GlobalConstant.KODE_BARCODE};
        Object[][] isi = new Object[listVoidDisplay.size()][2];
        int x = 0;
        int no = 0;
        double total = 0;
        for (Object voids : listVoidDisplay) {
            isi[x][0] = no += 1;
            isi[x][1] = voids;
            x++;
        }

        tableVoid.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;


            }
        });

        TableColumn column0 = tableData.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
    }

    private void bayar(String response, double kembali) {
        try {
            Penjualan penjualan = new Penjualan();
            if (comboTipePembayaran.getSelectedIndex() == 0) {
                penjualan.setTypeTransaksi((String) comboTipePembayaran.getSelectedItem());
                penjualan.setTypeBank(GlobalConstant.EMPTY_STRING);
            } else {
                penjualan.setTypeTransaksi((String) comboTipePembayaran.getSelectedItem());
                penjualan.setTypeBank((String) comboBank.getSelectedItem() + GlobalConstant.MIN + textNo.getText());
            }
            if (comboPembayaran.getSelectedIndex() == 0) {
                penjualan.setPembayaran((String) comboPembayaran.getSelectedItem());
            } else {
                penjualan.setPembayaran((String) comboPembayaran.getSelectedItem());
            }
            penjualan.setJatuhTempo(dateJatuhTempo.getDate());
            penjualan.setBayar(Double.parseDouble(response));
            penjualan.setTotal(totals);
            penjualan.setKembali(kembali);
            penjualan.setNoTransaksi(textNoTransaksi.getText());
            penjualan.setDateTransaksi(lockDateDAO.getDateToday());
            penjualan.setUserPenjualan(user.getUserName());
            penjualan.setDP(GlobalConstant.EMPTY_STRING.equals(textDP.getText()) ? new Double(0) : Double.parseDouble(textDP.getText()));
            penjualan.setMemberCustomer((MemberCustomer) listMemberCustomer.get(comboMemberCustomer.getSelectedIndex()));
            penjualanDAO.saveTransaksi(listPenjualan, penjualan);
            listPenjualan = penjualanDAO.getDataByEquals(Penjualan.class, "noTransaksi", penjualan.getNoTransaksi());
            PenjualanReport penjualanReport = new PenjualanReport();
            penjualanReport.invoicePenjualan(listPenjualan);
            penjualanReport.suratJalanPenjualan(listPenjualan);
            updateData();
        } catch (Exception ex) {
            Logger.getLogger(InvoiceFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
